Skip to main content

Create User

Create User Example

For creating a new user you need to use the createUser and provide a data object User

Check the example:

import AltibbiTelehealth

let newUser = User(
name: "Altibbi user",
email: "[email protected]",
dateOfBirth: "2000-01-30",
gender: "male", // Accepted Values: 'male' | 'female',
insuranceId: "123123123",
policyNumber: "111111111",
nationalityNumber: "11110000",
height: 180,
weight: 90,
bloodType: "A+", // Accepted Values: 'A+' | 'B+' | 'AB+' | 'O+' | 'A-' | 'B-' | 'AB-' | 'O-'
smoker: "yes", // Accepted Values: 'yes' | 'no'
alcoholic: "no", // Accepted Values: 'yes' | 'no'
maritalStatus: "single", // Accepted Values: 'single' | 'married' | 'divorced' | 'widow'
relationType: "brother" // Accepted Values: 'personal' | 'father' | 'mother' | 'sister' | 'brother' | 'child' | 'husband' | 'wife' | 'other',
)

ApiService.createUser(userData: newUser, completion: {user, failure, error in
// Handle user as a User object on success
// The error will represent an internal error that prevents the request
// The failure will represent an API request and could be handled by using ResponseFailure.printJsonData(failure)

// Check this handling just for example

if let error = error {
print("Data Error: \(String(describing: error))")
} else if let failure = failure {
// You can print failure data or handle it based on your logic
} else {
if let user = user {
print("User ID: \(user.id)")
}
}
})

Consider that not all User data are required

Responses

Status 201

Success

{
"id": 999999999,
"name": "Altibbi User",
"email": "[email protected]",
"date_of_birth": "2000-01-30",
"gender": "male",
"insurance_id": "123123123",
"policy_number": "111111111",
"nationality_number": "11110000",
"height": 180,
"weight": 90,
"blood_type": "A+",
"smoker": "yes",
"alcoholic": "no",
"maritalStatus": "single",
"relation_type": "brother"
}

Status 401

UnauthorizedHttpException represents an Unauthorized HTTP exception with status code 401.

{
"name": "Unauthorized",
"message": "Your request was made with invalid credentials",
"code": "0",
"status": "401",
"type": "yii\\web\\UnauthorizedHttpException"
}

Status 422

Data Validation Failed.

[
{
"field": "string",
"message": "string"
}
]